<template>
	<view style="padding-top: 100rpx;">
		<view class="text-outer" v-for=" (item ,index) in allArr" :key="index" @click="next(item)">
			<view class="text-count">{{item.arr.length}}</view>
			 <image :src="user.head_img" mode="" style="width: 60rpx;height: 60rpx;margin-right: 20rpx;"></image>
			<view> {{filterTime(item.time)}}</view>
			<view>用户 {{item.title}}了</view>
     
		</view>
	</view>
</template>

<script>
	import GoEasy from '@/lib/goeasy-2.4.6.min.js';
	export default {
		data() {
			return {
				list: [],
				user:'',
				allArr:[],//统计所有评论收藏
			}
		},
		filters: {
			showDate(value) {
				let date = new Date(value * 1000);
				var time = this.formatDate2(date, 'yyyy-MM-dd hh:mm:ss');
				return time
			}
		},

		onShow() {
			var that = this;
			this.user=uni.getStorageSync('user')
			const goEasy = GoEasy.getInstance({
				host: "hangzhou.goeasy.io",
				appkey: "BC-51a6d918cf0c48f9b997ac208d09a77b",
				allowNotification: true,
				modules: ['pubsub'],
			});
			goEasy.connect({
				onSuccess: function() {
				
				},
				onFailed: function(error) {
					console.log("Failed to connect GoEasy, code:" + error.code + ",error:" + error.content);
				},
				onProgress: function(attempts) {
					console.log("GoEasy is connecting", attempts);
				}
			});
			goEasy.pubsub.history({
				channel: 'my_channel', //必需项
				start: new Date(new Date(new Date().toLocaleDateString()).getTime()), //可选项，开始时间，默认为0，即从第一条消息开始查
				end: new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 -
					1), //可选项，结束时间,默认为当前时间
				limit: 10, //可选项，返回的消息条数，默认为10条，最多30条
				onSuccess: function(response) {
					var dArr=[];
					var pArr=[];
					var allArr=[];
					var list = JSON.stringify(response.content)
					that.list = JSON.parse(list)
					if(that.list.messages){
						that.list.messages.map((item)=>{
							if(item.content.includes('点赞')){
								dArr.push(item)
							}
							if(item.content.includes('评论')){
								pArr.push(item)
							}
						})
						var obj={
							title:dArr[0].content,
							time:dArr[0].time,
							arr:dArr
						}
						var obj2={
							title:pArr[0].content,
							time:pArr[0].time,
							arr:pArr
						}
						allArr.push(obj)
						allArr.push(obj2)
						that.allArr=allArr
					}
				
                    
				},
				onFailed: function(error) { //获取失败
					console.log("Failed to obtain history, code:" + error.code + ",error:" + error.content);
				},
			});

		},
		methods: {
			user() {
				return this.$store.state.user;
			},
			next(item){
				 console.log(222222222)
			uni.navigateTo({
				url:'/pages/video/pushDefault?arr='+JSON.stringify(item.arr)
			})
			},
			//转换时间
		filterTime(time) {
		var date = new Date(+time),
		    Y = date.getFullYear() + '-',
		    M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-',
		    D = date.getDate() + ' ',
		    h = date.getHours() + ':',
		    m = date.getMinutes() + ':',
		    s = date.getSeconds()
		    return Y + M + D   // '2022-05-20'
		  },

			 padLeftZero(str) {
				return ('00' + str).substr(str.length);
			},


		}

	}
</script>

<style>
	.text-outer {
		position: relative;
		width: 100%;
		display: flex;
		align-items: center;
		 /* justify-content: space-between; */
		line-height: 120rpx;
		height: 120rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		border-bottom: 1px solid #333;
		box-sizing: border-box;
	}
	.text-count{
		position: absolute;
		z-index: 100;
		left: 10%;
		top: 10%;
		width: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 30rpx;
		border-radius: 50%;
		background-color: red;
		color: #fff;
	}
</style>
